package edu.gatech.cs2340.aperturescience.backend;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * @author Jacob Morgan, Kefu Zhou, Kevin Lacey, Kelly Evanish
 * 
 *         Helper class for registering new users.
 */

public class TodoSQLiteHelper extends SQLiteOpenHelper {

	/**
	 * Constructor
	 * 
	 * @param context
	 */
	public TodoSQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	public final String TABLE_USERS = "users";
	public final String COLUMN_ID = "id";
	public final String COLUMN_USERNAME = "username";
	public final String COLUMN_NAME = "name";
	public final String COLUMN_PASSWORD = "password";
	public final String COLUMN_EMAIL = "email";

	public final String TABLE_CATEGORY = "categories";
	public final String COLUMN_CATEGORYUSER = "id";
	public final String COLUMN_CATEGORY = "category";

	public final String TABLE_TASK = "tasks";
	public final String COLUMN_TASKOWNER = "owner";
	public final String COLUMN_TASKID = "id";
	public final String COLUMN_TASKNAME = "name";
	public final String COLUMN_TASKDESCRIPTION = "description";
	public final String COLUMN_TASKCATEGORY = "category";
	public final String COLUMN_DUEDATE = "date";
	public final String COLUMN_COMPLETED = "completed";

	public static final String DATABASE_NAME = "todo.db";
	public static final int DATABASE_VERSION = 1;

	private final String SQL_CREATE_USERS = "create table " + TABLE_USERS + "("
			+ COLUMN_ID + " integer primary key autoincrement, "
			+ COLUMN_USERNAME + " varchar, " + COLUMN_PASSWORD + " varchar, "
			+ COLUMN_EMAIL + " varchar, " + COLUMN_NAME + " varchar)";
	private final String SQL_CREATE_CATEGORIES = "create table "
			+ TABLE_CATEGORY + "(" + COLUMN_CATEGORYUSER + " integer, "
			+ COLUMN_CATEGORY + " varchar)";
	private final String SQL_CREATE_TASKS = "create table " + TABLE_TASK + "("
			+ COLUMN_ID + " integer primary key autoincrement, "
			+ COLUMN_TASKOWNER + " integer, " + COLUMN_TASKNAME + " varchar, "
			+ COLUMN_TASKDESCRIPTION + " varchar, " + COLUMN_TASKCATEGORY
			+ " varchar, " + COLUMN_DUEDATE + " date, "+COLUMN_COMPLETED+" int)";

	/**
	 * onCreate manages database creation
	 */
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(SQL_CREATE_USERS);
		db.execSQL(SQL_CREATE_CATEGORIES);
		db.execSQL(SQL_CREATE_TASKS);

	}

	/**
	 * onUpgrade oversees smooth upgrade of the database
	 */
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

}
